package Server;



import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class DanhSachClients extends JPanel implements ListSelectionListener
{
	private JList<String> danhSachClients;
	private DefaultListModel<String> listModel;
	
	public DanhSachClients() {
		listModel = new DefaultListModel<String>();
		setDanhSachClients(new JList<String>(listModel));
		getDanhSachClients().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		getDanhSachClients().setSelectedIndex(0);
		getDanhSachClients().addListSelectionListener(this);
		getDanhSachClients().setVisibleRowCount(3);
		
		add(getDanhSachClients());
	}
	
	public void themPhanTu(String _tenPhanTu)
	{
		listModel.addElement(_tenPhanTu);
	}
	
	public void xoaPhanTu(String _tenPhanTu)
	{
		for (int i = 0; i < listModel.getSize(); i++)
		{
			if (listModel.get(i).equals(_tenPhanTu))
				listModel.remove(i);
		}
	}
	
	public boolean danhSachRong()
	{
		if (listModel.size() == 0)
			return true;
		else
			return false;
	}
	
	public String[] layDanhSachPhanTu()
	{
		String[] danhSach;
		danhSach = (String[]) listModel.toArray();
		return danhSach;
	}
	
	public int layIndexPhanTuDuocChon()
	{
		return danhSachClients.getSelectedIndex();
	}
	
	public String layGiaTriPhanTuDuocChon()
	{
		return danhSachClients.getSelectedValue();
	}
	
	@Override
	public void valueChanged(ListSelectionEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @return the danhSachClients
	 */
	public JList<String> getDanhSachClients() {
		return danhSachClients;
	}

	/**
	 * @param danhSachClients the danhSachClients to set
	 */
	public void setDanhSachClients(JList<String> danhSachClients) {
		this.danhSachClients = danhSachClients;
	}
}
